from selenium import webdriver
import time
from selenium.webdriver.common.by import By


driver = webdriver.Chrome("C:\Program Files\driver\chromedriver.exe")
driver.maximize_window()

driver.get("https://www.baidu.com")

elements = driver.find_elements(By.CSS_SELECTOR, "a[class^=title-content]")
elements[0].click()

# 获取所有窗口的句柄
handlers = driver.window_handles
print(handlers)
# 切换至最新页面
driver.switch_to.window(handlers[-1])

time.sleep(3)

driver.find_element(By.XPATH, "//em[text()='习近平主席中亚之行']/../../a[@tabindex='0' and text()='']").click()

# for element in elements:
#     element.click()
#     time.sleep(2)

# time.sleep(5)
# driver.close()
time.sleep(5)
driver.quit()

